package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.*;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.service.BannerService;
import com.system.healthproject.pojo.Banner;
import com.system.healthproject.pojo.BannerType;
import com.system.healthproject.pojo.Hospital;
import com.system.healthproject.utils.DateUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@Api(value = "BANNER" ,tags = "后端-广告数据接口api")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务错误")
})
@RequestMapping("/admin/banner")
public class    BannerControl {

    @Autowired
    private BannerService bannerService ;
    /**
     * 新增广告
     * @return
     */
    @RequestMapping(value = "/addBanner" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "新增BANNER(接口已调用)",notes = "新增广告",httpMethod = "post",response = ApiResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bannerTypeId",value = "广告类型ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "bannerDisplay",value = "展示端( 1 只展示患者端  2医生端 3 两者都展示)",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "bannerContent",value = "活动内容",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "bannerH5path",value = "H5链接地址",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "bannerImg",value = "BANNER图",paramType = "query",dataType = "String",required = true),
    })
    public  ApiResult conditionSelect(Integer bannerTypeId,Integer bannerDisplay,String bannerContent,String bannerH5path,String bannerImg ){
            String msg = bannerService.addBanner(bannerTypeId,bannerDisplay,bannerContent,bannerH5path,bannerImg);
        return ApiResult.success(msg);
    }


    /**
     * 查询广告类型ID和名称
     * @return
     */
     @RequestMapping(value = "/selectBannerType" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "查询BANNER类型ID和类型名称（接口已调用）",notes = "查询广告类型ID和类型名称",httpMethod = "post")
    public  ApiResult<List<BannerType>> selectBannerType(){
         List<BannerType> list = bannerService.selectBannerTypeIdName();

     return ApiResult.successWithData("成功",list);
    }


    /**
     * 查询Banner
     * @return
     */
    @RequestMapping(value = "/selectBanner" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "查询BANNER（条件查询）接口已调用",notes = "查询BANNER（条件查询）",httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bannertypeId",value = "广告类型",paramType = "query",dataType = "int",required = false),
            @ApiImplicitParam(name = "createStartTime",value = "创建时间",paramType = "query",dataType = "date",required = false),
            @ApiImplicitParam(name = "createEndTime",value = "创建时间",paramType = "query",dataType = "date",required = false),
            @ApiImplicitParam(name = "currentPage",value = "当前页",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "limit",value = "每页显示数据条数",paramType = "query",dataType = "int",required = true),
    })
    public  ApiResult<PagesBean<ResultBanner>> selectBanner(Integer bannertypeId,String createStartTime,String createEndTime,Integer currentPage,Integer limit){
       List<ResultBanner> list = bannerService.selectBanner(bannertypeId,createStartTime,createEndTime,currentPage,limit);
        PagesBean<ResultBanner> resultBannerPagesBean = new PagesBean<>();
        resultBannerPagesBean.setNowsPage(currentPage);
        resultBannerPagesBean.setPageSize(limit);
        Integer count  = bannerService.countBanner(bannertypeId,createStartTime,createEndTime);
        resultBannerPagesBean.setDataCount(count);
        resultBannerPagesBean.setData(list);
        return ApiResult.successWithData("成功",resultBannerPagesBean);
    }

    /**
     * 根据ID查询Banner详细信息
     * @return
     */
    @RequestMapping(value = "/selectById" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "根据ID查询Banner详细信息（接口已调用）",notes = "查询BANNER详情",httpMethod = "post")
    @ApiImplicitParam(name = "bannerId",value = "广告ID",paramType = "query",dataType = "int",required = true)
    public  ApiResult selectById(Integer bannerId){
        Banner banner= bannerService.selectById(bannerId);
        return ApiResult.successWithData("成功",banner);
    }


    /**
     * 删除banner
     * @return
     */
    @RequestMapping(value = "/delBanner" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "删除BANNER（接口已调用）",notes = "删除广告",httpMethod = "post",response = ApiResult.class)
    @ApiImplicitParam(name = "bannerId",value = "广告ID",paramType = "query",dataType = "int",required = true)
    public  ApiResult delBanner(Integer bannerId){
        String msg = bannerService.deleteBanner(bannerId);
        return ApiResult.success(msg);
    }

    /**
     * 修该banner
     * @return
     */
    @RequestMapping(value = "/updateBanner" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "修改BANNER（接口已调用）",notes = "修改广告",httpMethod = "post",response = ApiResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bannerId",value = "广告ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "bannerTypeId",value = "广告类型",paramType = "query",dataType = "int",required = false),
            @ApiImplicitParam(name = "bannerDisplay",value = "展示端( 1 只展示患者端  2医生端 3 两者都展示)",paramType = "query",dataType = "int",required = false),
            @ApiImplicitParam(name = "bannerContent",value = "活动内容",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "bannerH5path",value = "H5链接地址",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "bannerImg",value = "BANNER图",paramType = "query",dataType = "String",required = false),
    })
    public  ApiResult updateBanner(Integer bannerId,Integer bannerTypeId,Integer bannerDisplay,
                                   String bannerContent,String bannerH5path,String bannerImg){
         String msg =  bannerService.updateBanner(bannerId,bannerTypeId,bannerDisplay,bannerContent,bannerH5path,bannerImg);
        return ApiResult.success(msg);
    }
 /**
     * banner发布、下架
     * @return
     */
    @RequestMapping(value = "/releaseDismountBanner" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "banner发布、下架(接口已调用)",notes = "banner发布、下架",httpMethod = "post",response = ApiResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bannerId",value = "广告ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "bannerState",value = "展示状态（1、已上架  2、未上架）",paramType = "query",dataType = "int",required = true),
    })
    public  ApiResult releaseDismountBanner(Integer bannerId,Integer bannerState){
        String msg = bannerService.releaseDismountBanner(bannerId,bannerState);
        return ApiResult.success(msg);
    }

}
